﻿namespace StringsAndTextProcessing
{
    using System;

    class ExtractingPalindromes
    {
        // 1.2.13.20. Write a program that extracts from a given text all palindromes, e.g. "ABBA", "lamal", "exe".

        static void Main()
        {
            var someText = @"Write a program that extracts from a given text all palindromes, e.g. ""ABBA"", ""lamal"", ""exe"".";
            char[] splitSeparators = { ' ', ',', '.', '!', '\n', '\r' };
            var onlyWords = someText.Split(splitSeparators, StringSplitOptions.RemoveEmptyEntries);

            foreach (var word in onlyWords)
            {
                var isPalindrome = true;
                for (var j = 0; j < word.Length / 2; j++)
                {
                    if (word[j] != word[word.Length - j - 1])
                    {
                        isPalindrome = false;
                        break;
                    }
                }

                if (isPalindrome == true && word.Length > 1)
                {
                    Console.WriteLine(word);
                }
            }
        }
    }
}